package com.example.waimai.util;

import android.app.Activity;
import android.location.LocationListener;

import com.baidu.location.BDAbstractLocationListener;
import com.baidu.location.BDLocation;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.model.LatLng;
import com.example.waimai.context.UserInfoContext;

import java.util.HashMap;
import java.util.Map;

public class LocationUtil {


    public static Map<String,Object> onePostion(Activity activity){

       LocationClient mLocationClient = new LocationClient(activity.getApplicationContext());
       LocationClientOption mOption = new LocationClientOption();
       mLocationClient.setLocOption(mOption);
        // 注册一个监听函数
        mLocationClient.registerLocationListener(new BDAbstractLocationListener() {
            @Override
            public void onReceiveLocation(BDLocation bdLocation) {
                //UserInfoContext.currentAddr = bdLocation;
            }
        });
       mLocationClient.start();
       return null;
    }

    public static void startListener(Activity act){
        LocationClient mLocationClient = new LocationClient(act.getApplicationContext());
        LocationClientOption mOption = new LocationClientOption();
        mOption.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
        mOption.setCoorType("bd09ll");
        mOption.setScanSpan(0);
        mOption.setOpenGps(true);
        mOption.setLocationNotify(false);
        mOption.setIgnoreKillProcess(false);
        mOption.SetIgnoreCacheException(false);
        mOption.setWifiCacheTimeOut(5 * 60 * 1000);
        mOption.setEnableSimulateGps(false);
        mOption.setIsNeedAddress(true);
        mLocationClient.setLocOption(mOption);
        // 注册一个监听函数
        mLocationClient.registerLocationListener(new BDAbstractLocationListener() {
            @Override
            public void onReceiveLocation(BDLocation bdLocation) {
                UserInfoContext.currentLatLng = new LatLng(bdLocation.getLatitude(),bdLocation.getLongitude());
                mLocationClient.stop();
            }
        });
        mLocationClient.start();
    }

}
